<html>
<head>
    <script type="text/javascript" src="../libjs/Perl6/MetaModel.js"></script>
    <script type="text/javascript">
        require.INC = "../inc";    
        require('Test.Builder');
        require('Test.More'); 
        
        require.INC = "../libjs";    
        require('Perl6.MetaClass');   
        require('Perl6.Class');                
        require('Perl6.Instance');                        
    </script>           
</head>
<body>
<pre id='test'><script type="text/javascript">

plan({ tests : 20 });

var Foo = new Perl6.Class ('Foo-0.0.1-jsan:STEVAN', {
    'instance' : {
        'methods' : {
            'bar' : function () { return 'Foo.bar' }
        }
    }
});
isaOK(Foo, 'Perl6.Class');

var foo = new Perl6.Instance (Foo);
isaOK(foo, 'Perl6.Instance');

ok(foo.isa('Foo'), '... our class isa Foo');
ok(!foo.isa('Bar'), '... our class is not a Bar');

ok(foo.can('bar'), '... foo can bar()');
ok(!foo.can('baz'), '... foo cant baz()');

isaOK(foo.can('bar'), 'Perl6.Method');
is(call_method(foo, 'bar'), 'Foo.bar', '... foo.bar() returns "Foo.bar"');

// ...

var Bar = new Perl6.Class ('Bar-0.0.1-jsan:STEVAN', { 
    'is' : [ Foo ],
    'instance' : {
        'methods' : {
            'foo' : function () { return 'Bar.foo' }
        }
    }    
});
isaOK(Bar, 'Perl6.Class');

var bar = new Perl6.Instance (Bar);
isaOK(bar, 'Perl6.Instance');

ok(bar.isa('Bar'), '... our class isa Bar');
ok(bar.isa('Foo'), '... our class isa Foo');
ok(!bar.isa('Baz'), '... our class is not a Baz');

ok(bar.can('foo'), '... bar can bar()');
ok(bar.can('bar'), '... bar can bar()');
ok(!bar.can('baz'), '... bar cant baz()');

isaOK(bar.can('bar'), 'Perl6.Method');
is(call_method(bar, 'bar'), 'Foo.bar', '... bar.bar() returns "Foo.bar"');

isaOK(bar.can('foo'), 'Perl6.Method');
is(call_method(bar, 'foo'), 'Bar.foo', '... bar.foo() returns "Bar.foo"');


</script></pre>
</body>
</html>
